home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 05 - 1989 / 05.03 Mar 89 / calc source / DoCalc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-09  |  3.2 KB  |  87 lines  |  [TEXT/KAHL]

  1.  
  2. #include <WindowMgr.h>
  3. #include <ListMgr.h>
  4. #include <OSUtil.h>
  5. #include <EventMgr.h>
  6.  
  7. #include "MacCalc.h"
  8. #include "CalcData.h"
  9. #include "Parser.h"
  10.  
  11. void DoCalc( sheet_record_hdl )
  12. SHEET_WIN_HDL sheet_record_hdl ;
  13. {
  14.     int i, j ;
  15.     Str255 buffer ;
  16.     Cell curr_cell ;
  17.     int error ;
  18.     char *err_mess ;
  19.     
  20.     /* Lock and dereference the handle */
  21.     HLock( (Handle)sheet_record_hdl ) ;
  22.     curr_sheet_ptr = *sheet_record_hdl ;
  23.     
  24.     /* Process all cells */
  25.     for( i=0;i<MAX_ROWS;i++ ) {
  26.         for( j=0;j<MAX_COLUMNS;j++) {
  27.             switch( curr_sheet_ptr->sheet_data[i][j].type ) {
  28.             /* If cell type is undefined then do nothing */
  29.             case UNDEFINED:
  30.                 break ;
  31.             /* If cell type is undefined then clear cell */
  32.             case CLEARED:
  33.                 SetPt( &curr_cell, j+1, i+1 ) ;
  34.                 LClrCell( curr_cell, curr_sheet_ptr->sheet_list_hdl ) ;
  35.                 curr_sheet_ptr->sheet_data[i][j].type = UNDEFINED ;
  36.                 break ;
  37.             /* If cell type is string then put string in cell */
  38.             case STRING:
  39.                 SetPt( &curr_cell, j+1, i+1 ) ;
  40.                 LSetCell( &curr_sheet_ptr->sheet_data[i][j].formula[1],
  41.                           curr_sheet_ptr->sheet_data[i][j].formula[0],
  42.                           curr_cell,
  43.                           curr_sheet_ptr->sheet_list_hdl ) ;
  44.                 break ;
  45.             case CONSTANT:
  46.                 SetPt( &curr_cell, j+1, i+1 ) ;
  47.                 curr_sheet_ptr->sheet_data[i][j].value = 
  48.                     GetFloat( curr_sheet_ptr->sheet_data[i][j].formula, &error ) ;
  49.                 if( error ) {
  50.                     Alert( error, NULL ) ;
  51.                     err_mess = "\p***ERROR***" ;
  52.                     LSetCell( err_mess+1, *err_mess, curr_cell, 
  53.                                 curr_sheet_ptr->sheet_list_hdl ) ;
  54.                 }else{
  55.                     ftoa( curr_sheet_ptr->sheet_data[i][j].value, buffer ) ;
  56.                     LSetCell( &buffer[1],
  57.                           buffer[0],
  58.                           curr_cell,
  59.                           curr_sheet_ptr->sheet_list_hdl ) ;
  60.                 }
  61.                 break ;
  62.             /* Parse formula then convert value to string and put in cell */
  63.             case FORMULA:
  64.                 SetPt( &curr_cell, j+1, i+1 ) ;
  65.                 curr_sheet_ptr->sheet_data[i][j].value = 
  66.                     ParseFormula( curr_sheet_ptr->sheet_data[i][j].formula, &error ) ;
  67.                 if( error ) {
  68.                     Alert( error, NULL ) ;
  69.                     err_mess = "\p***ERROR***" ;
  70.                     LSetCell( err_mess+1, *err_mess, curr_cell, 
  71.                                 curr_sheet_ptr->sheet_list_hdl ) ;
  72.                 }else{
  73.                     ftoa( curr_sheet_ptr->sheet_data[i][j].value, buffer ) ;
  74.                     LSetCell( &buffer[1],
  75.                           buffer[0],
  76.                           curr_cell,
  77.                           curr_sheet_ptr->sheet_list_hdl ) ;
  78.                 }
  79.                 break ;
  80.             }
  81.         }
  82.     }
  83.     calc_data = FALSE ;
  84.     DrawGrid( curr_sheet_ptr->sheet_window_ptr ) ;
  85.     HUnlock( (Handle)sheet_record_hdl ) ;
  86.     return ;
  87. }